using System.Threading;

namespace System
{
	public static class Singleton<TItem>
	where TItem : class, new()
	{
		private static TItem _Instance;

		static Singleton()
		{
			_Instance = default(TItem);
		}

		public static TItem GetInstance()
		{
			if (_Instance == null)
			{
				TItem tItem = default(TItem);
				Interlocked.CompareExchange<TItem>(ref _Instance, Activator.CreateInstance<TItem>(), tItem);
			}
			return _Instance;
		}
	}
}